use ane_macros::create_table;
use sea_orm::{ConnectionTrait, DbConn, EntityTrait, Schema, TransactionTrait};

/// 创建相关表格
///
/// 简单判断表格是否存在，不存在则创建
pub async fn init_db(db: &DbConn) -> Result<(), sea_orm::DbErr> {
    let builder = db.get_database_backend();
    let schema = Schema::new(builder);
    let txn = db.begin().await?;
    use crate::entity::{cms_article, cms_article_category, cms_category, cms_topic};
    create_table!(cms_topic, txn, builder, schema);
    create_table!(cms_article, txn, builder, schema);
    create_table!(cms_category, txn, builder, schema);
    create_table!(cms_article_category, txn, builder, schema);
    txn.commit().await?;
    Ok(())
}
